package org.example.myframework.frame.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.myframework.frame.common.entity.R;
import org.example.myframework.frame.common.log.annotation.aop.LogAnnotation;
import org.example.myframework.frame.demo.domain.base.PageRo;
import org.example.myframework.frame.demo.domain.entity.TestTable;
import org.example.myframework.frame.demo.domain.entity.TestTablePlus;
import org.example.myframework.frame.demo.service.TestTablePlusService;
import org.example.myframework.frame.demo.service.TestTableService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/test")
@RestController
@Api(value = "测试接口", tags = {"测试接口"})
public class TestController {

    @Resource
    private TestTableService testTableService;
    @Resource
    private TestTablePlusService testTablePlusService;

    @LogAnnotation(value = "测试接口")
    @GetMapping("/test")
    @ApiOperation(value = "测试接口")
    public String test() {
        return "test";
    }

    /**
     * 集成mybatis测试
     * @return 测试列表
     */
    @LogAnnotation(value = "获取测试列表")
    @GetMapping("/getTestList")
    @ApiOperation(value = "获取测试列表")
    public List<TestTable> getList() {
        return testTableService.getList();
    }

    /**
     * 分页
     */
    public void getPlusPage() {
        PageRo<TestTablePlus> ro = new PageRo<>();
        // PageVo<TestTablePlus> pageVo = testTablePlusService.getPage(ro);
    }

    /**
     * 统一返回结果测试
     */
    @GetMapping("/getTestListONR")
    @ApiOperation(value = "获取测试列表 - 统一返回结果")
    public R<List<TestTable>> getListONR() {
        return R.ok(testTableService.getList());
    }

    /**
     * 统一异常处理
     */
    @GetMapping("/testUnifiedException")
    @ApiOperation(value = "测试 - 统一异常处理")
    public R<Void> testUnifiedException() {
        // throw new RuntimeException(SystemExceptionEnum.NOTFOUND.getMsg(), new Throwable(String.valueOf(SystemExceptionEnum.NOTFOUND.getCode())));
        // throw new RuntimeException(new Throwable(String.valueOf(SystemExceptionEnum.NOTFOUND.getMsg())));
        if ( 1 == 1 ) {
            testTablePlusService.throwExceptionTest();
            // throw new SystemException(SystemExceptionEnum.NOTFOUND);
        }
        return R.ok();
    }
}
